package com.os.start.mapper;

import com.os.start.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Matt on 2022-01-04.
 * 通过注解方式实现DAO
 */
@Mapper
public interface UserInfoAnnotationDao {

    @Select("  SELECT id, name AS name, sex, age FROM s_User ")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "age", column = "age")
    })
    List<UserInfo> queryUser();

    @Select("  SELECT id, name AS name, sex, age FROM s_User " +
            "  WHERE id = #{id}")
    UserInfo getUserById(@Param("id") String id);

    @Update("  UPDATE s_User SET name = #{user.name}, sex = #{user.sex}, age = #{user.age} " +
            "  WHERE id = #{user.id}")
    int updateUser(@Param("user") UserInfo userInfo);

    @Insert("  INSERT INTO s_User(name, sex, age, id) " +
            "  VALUES(#{user.name}, #{user.sex}, #{user.age}, #{user.id})")
    int insertUser(@Param("user") UserInfo userInfo);

    @Delete("  DELETE FROM s_User WHERE id = #{id}")
    int deleteUserById(@Param("id") String id);


}
